<!DOCTYPE html>
<html>
<div id="editForm">
  <div class="form-group">
    <label class="control-label col-xs-3 is-required">字段名称</label>
    <div class="col-xs-8">
      <div class="input-icon right">
        <input type="text" required id="field_name_txt" name="name" field="name" class="form-control"/>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-xs-3">描述信息</label>
    <div class="col-xs-8">
      <div class="input-icon right">
        <input type="text" id="field_desc_txt" name="desc" field="desc" class="form-control"/>
      </div>
    </div>
  </div>
  <div id="fixedField_div">
    <div class="form-group">
      <label class="control-label col-xs-3 is-required">字段长度</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" required value="-1" id="fixed_field_len_txt" name="len" field="len"/>
        </div>
      </div>
    </div>
    <div id="fixed_unpack_div">
      <div class="form-group">
        <label class="control-label col-xs-3">偏移量</label>
        <div class="col-xs-8">
          <div class="input-icon right">
            <input type="text" class="form-control" value="-1" id="fixed_field_offset_txt" name="offset" field="offset"/>
          </div>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">填充字符</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="fixed_field_fillChar_txt" name="fillChar" field="fillChar"/>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">填充类型</label>
      <div class="col-xs-8" style="margin-bottom: 0px;">
        <select id="fillType_select" name="fillType" field="fillType" class="form-control select2">
          <option value="char">字符</option>
          <option value="byte">字节</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">填充方向</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <select id="fixed_field_fillLocation_select" name="fillLocation" field="fillLocation" class="form-control select2">
            <option value="left">左边填充</option>
            <option value="right">右边填充</option>
          </select>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">缺省值</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="fixed_field_defVal_txt" name="defVal" field="defVal"/>
        </div>
      </div>
    </div>
  </div>


  <div id="delim_Field_div">
    <div class="form-group">
      <label class="control-label col-xs-3 is-required">分隔符字符</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" value="-1" id="delim_field_delimChar_txt" name="delimChar" field="delimChar" required/>
        </div>
      </div>
    </div>
    <div id="fixed_unpack_div">
      <div class="form-group">
        <label class="control-label col-xs-3">需要转义的字符串</label>
        <div class="col-xs-8">
          <div class="input-icon right">
            <input type="text" class="form-control" value="-1" id="delim_field_escapeChar_txt" name="escapeChar" field="escapeChar"/>
          </div>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">转义中文特殊字符</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <select id="delim_field_escapeZh_select" name="escapeZh" field="escapeZh" class="form-control select2">
            <option value="true">是</option>
            <option value="false">否</option>
          </select>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-xs-3">转义字符</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="delim_field_escapePrefix_txt" value="\" name="escapePrefix" field="escapePrefix"/>
        </div>
      </div>
    </div>

    <div class="form-group" id="escapeSkipped_div">
      <label class="control-label col-xs-3">跳过字段数</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="escapeSkipped_txt" name="escapeSkipped" field="escapeSkipped"/>
        </div>
      </div>
    </div>

    <div class="form-group">
      <label class="control-label col-xs-3">缺省值</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="escapeDefVal_txt" name="defVal" field="defVal"/>
        </div>
      </div>
    </div>

  </div>
  <div id="xml_field_div">
    <div class="form-group" id="xml_field_value_div">
      <label class="control-label col-xs-3">字段值 </label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="xml_field_value_txt" name="value" field="value"/>
        </div>
      </div>
    </div>

    <div class="form-group">
      <label class="control-label col-xs-3 is-required" id="xml_field_xpath_title">xpath</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="xml_field_xpath_txt" name="xpath" field="xpath" required/>
        </div>
      </div>
    </div>
  </div>
  <div id="cnpas12_field_div">
    <div class="form-group">
      <label class="control-label col-xs-3" id="cnpas12_field_div_tag">tag 值</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="cnaps12_field_tag_txt" name="tag" field="tag" required/>
        </div>
      </div>
    </div>
    <div class="form-group" id="len_cnpas12_field_div">
      <label class="control-label col-xs-3 is-required">长度</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="cnpas12_field_len_txt" name="len_cnpas12" field="len_cnpas12" required/>
        </div>
      </div>
    </div>

    <div class="form-group" id="deVal_cnpas12_field_div">
      <label class="control-label col-xs-3">缺省值</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="cnpas12_field_defVal_txt" name="defVal_cnpas12" field="defVal_cnpas12"/>
        </div>
      </div>
    </div>
  </div>
  <div id="deVal_json_field_div">
    <div class="form-group">
      <label class="control-label col-xs-3">缺省值</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="json_field_defVal_txt" name="defVal_json" field="defVal_json"/>
        </div>
      </div>
    </div>
  </div>
  <div id="http_field_div">
    <div class="form-group">
      <label class="control-label col-xs-3 is-required">参数名称</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="http_field_tag_txt" name="tag" field="tag" required/>
        </div>
      </div>
    </div>
  </div>

  <div id="iso8583_field_div">
    <div class="form-group">
      <label class="control-label col-xs-3 is-required">字段序号</label>
      <div class="col-xs-8">
        <div class="input-icon right">
          <input type="text" class="form-control" id="iso8583_field_tag_txt" name="iso8583tag" field="iso8583tag" required/>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">

  $(function () {
    //报文类型
    var nodeType = getPolicyType(pktSelectNode);
    //处理类型：解包unpack,解包：pack
    var processType = pktSelectNode.rootType;
	//初始化页面
	init(nodeType, processType);
    if (pktSelectNode.dataModel){
      applyDrawing('#editForm',pktSelectNode.dataModel)
    }


  })


  function hideAllDiv() {
    hideAll("fixedField_div");
    hideAll("delim_Field_div");
    hideAll("xml_field_div");
    hideAll("cnpas12_field_div");
    hideAll("http_field_div");
    hideAll("deVal_json_field_div");
    hideAll("iso8583_field_div");
  }

  function init(nodeType, processType) {
    hideAllDiv();
    //处理定长报文
    initFixedField(nodeType, processType);
    //处理分隔符报文
    initDelimField(nodeType, processType);
    //处理xml报文
    initXmlField(nodeType, processType);
    //处理cnpas1,cnpas2报文
    initCnapsField(nodeType, processType);
    //处理http报文
    initHttpField(nodeType, processType);
    //处理json报文
    initJsonField(nodeType, processType);
    //处理ISO8583报文
    initIso8583Field(nodeType, processType);
  }

  /**
   * 处理iso8583报文
   */
  function initIso8583Field(nodeType, processType) {
    if (nodeType == "iso8583") {
      hideAll("fixedField_div");
      hideAll("delim_Field_div");
      hideAll("cnpas12_field_div");
      hideAll("http_field_div");
      hideAll("xml_field_div");
      hideAll("deVal_json_field_div");
      disabledAll("fixedField_div");
      disabledAll("delim_Field_div");
      disabledAll("cnpas12_field_div");
      disabledAll("http_field_div");
      disabledAll("xml_field_div");
      disabledAll("deVal_json_field_div");
      enableAll("iso8583_field_div");
      showAll("iso8583_field_div");
    }
  }

  /**
   * 处理json报文
   */
  function initJsonField(nodeType, processType) {
    if (nodeType == "json") {
      hideAll("fixedField_div");
      hideAll("delim_Field_div");
      hideAll("cnpas12_field_div");
      hideAll("http_field_div");
      hideAll("iso8583_field_div");
      disabledAll("fixedField_div");
      disabledAll("delim_Field_div");
      disabledAll("cnpas12_field_div");
      disabledAll("http_field_div");
      disabledAll("iso8583_field_div");

      enableAll("xml_field_div");
      showAll("xml_field_div");
      enableAll("deVal_json_field_div");
      showAll("deVal_json_field_div");
      //就该界面 隐藏 字段值  与  xpath 修改为 path
      $("#xml_field_value_div").hide();
      disabledAll("xml_field_value_div");
      $("#xml_field_xpath_title").html("path");
	   $("#xml_field_xpath_txt").attr("name","path");
	   $("#xml_field_xpath_txt").attr("field","path");
    }
  }

  /**
   * 处理http报文
   */
  function initHttpField(nodeType, processType) {
    if (nodeType == "http") {
      hideAll("fixedField_div");
      hideAll("delim_Field_div");
      hideAll("xml_field_div");
      hideAll("cnpas12_field_div");
      hideAll("deVal_json_field_div");
      hideAll("iso8583_field_div");
      disabledAll("fixedField_div");
      disabledAll("delim_Field_div");
      disabledAll("xml_field_div");
      disabledAll("cnpas12_field_div");
      disabledAll("deVal_json_field_div");
      disabledAll("iso8583_field_div");
      enableAll("http_field_div");
      showAll("http_field_div");
    }
  }

  /**
   * 处理cnpas1,cnpas2报文
   */
  function initCnapsField(nodeType, processType) {
    if (nodeType == "cnaps1" || nodeType == "cnaps2") {
      hideAll("fixedField_div");
      hideAll("delim_Field_div");
      hideAll("xml_field_div");
      hideAll("http_field_div");
      hideAll("deVal_json_field_div");
      hideAll("iso8583_field_div");
      disabledAll("fixedField_div");
      disabledAll("delim_Field_div");
      disabledAll("xml_field_div");
      disabledAll("http_field_div");
      disabledAll("deVal_json_field_div");
      disabledAll("iso8583_field_div");
      enableAll("cnpas12_field_div");
      showAll("cnpas12_field_div");

      $("#cnpas12_field_div_tag").addClass('is-required');
      $("#cnaps12_field_tag_txt").attr("required", "true");
      //增加tag校验规则
      jQuery.validator.addMethod("cnapsLen",function(value,element){
        var reg = /^[0-9]+[a-zA-Z]$/;
        return !reg.test(value) || value.length <= 1
      },"长度必须大于1且最后一个字符必须为字母！");
      $("#cnaps12_field_tag_txt").rules("remove");
      $("#cnaps12_field_tag_txt").rules("add", {required: true, cnapsLen: true});

      if (nodeType == "cnaps2") {
        enableAll("xml_field_div");
        showAll("xml_field_div");
        $("#xml_field_xpath_title").html("xpath");
		$("#xml_field_xpath_txt").attr("name","xpath");
		$("#xml_field_xpath_txt").attr("field","xpath");
        //移除 tag 必选条件
        $("#cnpas12_field_div_tag").removeClass("is-required");
        $("#cnaps12_field_tag_txt").removeAttr("required");

        //取消tag校验规则
        $("#cnaps12_field_tag_txt").rules("remove");

        hideAll("len_cnpas12_field_div");
        disabledAll("len_cnpas12_field_div");
        hideAll("deVal_cnpas12_field_div");
        disabledAll("deVal_cnpas12_field_div");
      }
    }
  }

  /**
   * 处理xml报文
   */
  function initXmlField(nodeType, processType) {
    if (nodeType == "xml") {
      hideAll("fixedField_div");
      hideAll("delim_Field_div");
      hideAll("cnpas12_field_div");
      hideAll("http_field_div");
      hideAll("deVal_json_field_div");
      hideAll("iso8583_field_div");
      disabledAll("fixedField_div");
      disabledAll("delim_Field_div");
      disabledAll("cnpas12_field_div");
      disabledAll("http_field_div");
      disabledAll("deVal_json_field_div");
      disabledAll("iso8583_field_div");
      enableAll("xml_field_div");
      showAll("xml_field_div");
      $("#xml_field_xpath_title").html("xpath");
	  $("#xml_field_xpath_txt").attr("name","xpath");
	  $("#xml_field_xpath_txt").attr("field","xpath");
    }
  }

  /**
   * 处理分隔符报文
   */
  function initDelimField(nodeType, processType) {
    if (nodeType == "delim") {
      hideAll("fixedField_div");
      hideAll("xml_field_div");
      hideAll("cnpas12_field_div");
      hideAll("http_field_div");
      hideAll("deVal_json_field_div");
      hideAll("iso8583_field_div");
      disabledAll("fixedField_div");
      disabledAll("xml_field_div");
      disabledAll("cnpas12_field_div");
      disabledAll("http_field_div");
      disabledAll("deVal_json_field_div");
      disabledAll("iso8583_field_div");
      enableAll("delim_Field_div");
      showAll("delim_Field_div");
      if (processType == "pack") {
        hideAll("escapeSkipped_div");
        disabledAll("escapeSkipped_div");
      } else {
        enableAll("escapeSkipped_div");
        showAll("escapeSkipped_div");
      }
    }
  }

  //处理定长报文
  function initFixedField(nodeType, processType) {
    if (nodeType == "fixed") {
      hideAll("delim_Field_div");
      hideAll("xml_field_div");
      hideAll("cnpas12_field_div");
      hideAll("http_field_div");
      hideAll("deVal_json_field_div");
      hideAll("iso8583_field_div");
      disabledAll("delim_Field_div");
      disabledAll("xml_field_div");
      disabledAll("cnpas12_field_div");
      disabledAll("http_field_div");
      disabledAll("deVal_json_field_div");
      disabledAll("iso8583_field_div");
      enableAll("fixedField_div");
      showAll("fixedField_div");
      if (processType == "pack") {
        hideAll("fixed_unpack_div");
        disabledAll("fixed_unpack_div");
      } else if (processType == "pack") {
        enableAll("fixedField_div");
        showAll("fixedField_div");
      }
    }
  }



</script>
